import React, { useState } from 'react';
import { Layout, Form, Input, Button } from 'antd';
import { getUserId } from '@/utils/userId';
import { studentRegisterAPI } from '@/api/student';

const { Header, Content, Footer } = Layout;

const Register = () => {
  const [form] = Form.useForm();
  const [registered, setRegistered] = useState(false);

  const onFinish = async(values) => {
    console.log('Received values:', values);
    const userId =getUserId()
    await studentRegisterAPI({
      ...values,
      userId:userId
    })
    setRegistered(true);
  };

  const handleReturn = () => {
    setRegistered(false);
    form.resetFields();
  };

  return (
    <Layout>
      <Header style={{ color: 'white' }}>学员个人信息注册</Header>
      <Content style={{ padding: '10 50px' }}>
        <div style={{ background: '#fff', padding: 24, minHeight: 280 }}>
          {registered ? (
            <div>
              <h1>注册成功！</h1>
              <p>您已成功注册个人信息。</p>
              <Button onClick={handleReturn}>返回</Button>
            </div>
          ) : (
            <Form form={form} layout="vertical" initialValues={{}} onFinish={onFinish}>
              <Form.Item
                label="姓名"
                name="name"
                rules={[{ required: true, message: '请输入姓名' }]}
              >
                <Input />
              </Form.Item>
              <Form.Item
                label="年龄"
                name="age"
                rules={[{ required: true, message: '请输入年龄' }]}
              >
                <Input type="number" />
              </Form.Item>
              <Form.Item
                label="身份证号码"
                name="idCard"
                rules={[{ required: true, message: '请输入身份证号码' }]}
              >
                <Input />
              </Form.Item>
              <Form.Item>
                <Button type="primary" htmlType="submit">注册</Button>
              </Form.Item>
            </Form>
          )}
        </div>
      </Content>
      <Footer>
     <div style={{position:'absolute',left:'50%'}}>驾校管理系统&copy;2024-2099</div>
   </Footer>
    </Layout>
  );
};

export default Register;